﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VQWEB.administrator.sources;
using VQData;
using System.Data;

namespace VQWEB.administrator.english.lectures
{
    public partial class lecture_table_add : System.Web.UI.Page
    {
        EnglishData EnglishData = new EnglishData();
        eng_lectures_table eng_lectures_table = null;
        int Id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (RouteData.Values["Id"] != null)
                int.TryParse(RouteData.Values["Id"].ToString(), out Id);
            if (Id > 0)
            {
                frmLectureTable.DefaultMode = FormViewMode.Edit;
                eng_lectures_table = EnglishData.GetLectureTableById(Id);
                //news = NewsData.GetNewsById(Id);
                frmLectureTable.DataSource = new List<eng_lectures_table> { eng_lectures_table };
                frmLectureTable.DataBind();
            }
            else frmLectureTable.DefaultMode = FormViewMode.Insert;
        }

        protected void frmLectureTable_ItemCreated(object sender, EventArgs e)
        {
            var control = frmLectureTable.Row.FindControl("ltrLevel") as Literal;
            control.Text = ShowLevel();
        }

        private string ShowLevel()
        {
            int Id = 0;
            if (eng_lectures_table != null && eng_lectures_table.level_lecture_id.HasValue)
            {
                Id = eng_lectures_table.level_lecture_id.Value;
            }
            string html = string.Empty;
            DataTable table = EnglishData.ViewLectureLevels();
            if (table != null)
            {
                html += "<select name=\"level_lecture_id\" class=\"form-control\">";
                foreach (DataRow item in table.Rows)
                {
                    string selected = string.Empty;
                    int level_lecture_id = (int)item["level_lecture_id"];
                    string level_lecture_title = (string)item["level_lecture_title"];
                    if (Id == level_lecture_id)
                        selected = "selected=\"selected\"";
                    html += "<option " + selected + " value=" + level_lecture_id + ">" + level_lecture_title + "</option>";
                }
                html += "</select>";
            }
            return html;
        }
    }
}